// run: $exec < input
// opt:	0
// flag: -g
#include <iostream>

int const maxn = 100;
unsigned long long f[maxn], len[maxn];

void init()
{
	f[1] = 1;
	for (int i = 2; i < maxn; i++) {
		f[i] = len[i - 1] + 1;
		len[i] = len[i - 1] * 2 + 1;
	}
}

unsigned long long calc2(int n, unsigned long long l, bool rev)
{
	if (l <= 0) return 0;
	if (n < 0) return 0;
	if (l == len[n]) return f[n];
	if (l <= len[n - 1]) return calc2(n - 1, l, rev);
	if (!rev) {
		unsigned long long ret = f[n] + 1;
		if (l >= len[n] + 1)
			ret += calc2(n - 1, l - len[n] - 1, true);
		return ret;
	} else {
		unsigned long long ret = len[n] - f[n] + 1;
		if (l > len[n] + 1)
			ret += calc2(n - 1, l - len[n] - 1, true);
		return ret;
	}
}

unsigned long long calc(unsigned long long l)
{
	if (!l) return 0;
	int i = 1;
	for (; i < maxn; i++) if (len[i] > l) break;
	i--;
	return calc2(i, l, false);
}

int main()
{
	init();
	int T; std::cin >> T;
	while (T--) {
		unsigned long long l, r;
		std::cin >> l >> r;
		std::cout << calc(r) - calc(l - 1) << '\n';
	}
}

